/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *
 * web http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/
 */
(function($){
$(document).ready(function(){
  var currentPositionB = 0;
  var slideWidthB = 200;
  var slidesB = $('.slideBanner');
  var numberOfSlidesB = slidesB.length;

  // Remove scrollbar in JS
  $('#slidesContainerBanner').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slidesB
  .wrapAll('<div id="slideInnerBanner"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidthB
  });

  // Set #slideInner width equal to total width of all slides
  $('#slideInnerBanner').css('width', slideWidthB * numberOfSlidesB);

  // Insert left and right arrow controls in the DOM
  $('#slideshowBanner')
    .prepend('<span class="controlBanner" id="leftControlBanner">Move left</span')
    .append('<span class="controlBanner" id="rightControlBanner">Move right</span');

  // Hide left arrow control on first load
  manageControls(currentPositionB);

  // Create event listeners for .controls clicks
  $('.controlBanner')
    .bind('click', function(){
    // Determine new position
      currentPositionB = ($(this).attr('id')=='rightControlBanner')
    ? currentPositionB+1 : currentPositionB-1;

      // Hide / show controls
      manageControls(currentPositionB);
      // Move slideInner using margin-left
      $('#slideInnerBanner').animate({
        'marginLeft' : slideWidthB*(-currentPositionB)
      });
    });

  // manageControls: Hides and shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ $('#leftControlBanner').hide() }
    else{ $('#leftControlBanner').show() }
    // Hide right arrow if position is last slide
    if(position==numberOfSlidesB-1){ $('#rightControlBanner').hide() }
    else{ $('#rightControlBanner').show() }
    }
  });
})(jQuery);

